package project.active;

import model.pojo.Employee;
import project.dao.CommentDAO;
import project.dao.EmployeeDAO;
import project.dao.ProjectDAO;
import project.dao.TestProjectDAO;
import project.model.PrComment;
import project.model.PrProject;
import project.model.PrTestProject;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import approve.action.R;

public class Lvcomdetail extends Activity {
	Bundle language;
	String lang="EN",database="admin";
	PrProject pr =new PrProject();
	ProjectDAO prodao=new ProjectDAO();
	EmployeeDAO emdao=new EmployeeDAO();
	TestProjectDAO errdao= new TestProjectDAO();
	Employee emp=new Employee();
	CommentDAO comdao=new CommentDAO();
	TextView logout,username;
	Button btgoErrlist,btgoCom;
	TextView proinfo,errinfo,emcode,datecomde,noidung,lbdate,lbnoidung,lbemcode;

	
	PrTestProject oneer=null;
	PrComment onec=null;
	Spannable WordtoSpan;
	String tnv="";
	public String getDatabase() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			database = extras.getString("database");
		}
		return database;
	}
	
	public String getLang() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			lang = extras.getString("lang");
		}
		return lang;
	}
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lvcomdetail);
		language = getIntent().getExtras().getBundle(getLang());
		
		btgoErrlist=(Button)findViewById(R.id.l_bt_ComdetogoErrList);
		btgoCom=(Button)findViewById(R.id.l_bt_goCom);
		proinfo=(TextView)findViewById(R.id.l_lv_Pro);
		errinfo=(TextView)findViewById(R.id.l_lv_er);
		emcode=(TextView)findViewById(R.id.l_tv_emcomde);
		datecomde=(TextView)findViewById(R.id.l_tv_datecomde);
		noidung=(TextView)findViewById(R.id.l_tv_noidung);
		lbdate=(TextView)findViewById(R.id.l_tv_lb_date);
		lbemcode=(TextView)findViewById(R.id.l_tv_lb_emcomde);
		lbnoidung=(TextView)findViewById(R.id.l_tv_lb_noidung);
		
		btgoErrlist.setText(language.getString("l_errinfo"));
		btgoCom.setText(language.getString("l_commentlist"));
		lbdate.setText(language.getString("ac_report_ThoiGian"));
		lbemcode.setText(language.getString("tester"));
		lbnoidung.setText(language.getString("comment"));
		
		Intent i=this.getIntent();
		pr=(PrProject)i.getSerializableExtra("project");		
		emp=(Employee)i.getSerializableExtra("em");
		oneer=(PrTestProject)i.getSerializableExtra("oneerr");
		onec=(PrComment)i.getSerializableExtra("onecom");
		
		logout=(TextView)findViewById(R.id.logout);
		username=(TextView)findViewById(R.id.username);
		logout.setText(language.getString("Logout"));
		
		logout.setOnClickListener(listenerLogout);
		username.setText(emp.getUserName());
		
		
		proinfo.setText(language.getString("project")+": "+pr.getIdProject()+" - "+pr.getNameProject());
		
		tnv=language.getString("error")+": "+oneer.getIdTest();
		WordtoSpan = new SpannableString(tnv);        
		WordtoSpan.setSpan(new ForegroundColorSpan(Color.parseColor(oneer.getColorText())), 0, tnv.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		errinfo.setText(WordtoSpan);
		
		btgoErrlist.setOnClickListener(goErrlist);
		btgoCom.setOnClickListener(goCom);
		
		emcode.setText(onec.getEmployeeName());
		datecomde.setText(onec.getDisplayDate1());
		
		tnv=onec.getCommentview();
		WordtoSpan = new SpannableString(tnv);        
		WordtoSpan.setSpan(new ForegroundColorSpan(Color.parseColor(onec.getColorText())), 0, tnv.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		noidung.setText(WordtoSpan);
		
	}
	
	private OnClickListener goErrlist = new OnClickListener() {
		
		
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent i=new Intent(Lvcomdetail.this, Lverrorlist.class);
			i.putExtras(getIntent().getExtras());
			i.putExtra("em",emp);
			i.putExtra("lang", getLang());
			i.putExtra("database", getDatabase());
			i.putExtra("project", pr);
			
			startActivity(i);
		}
	};
	
	private OnClickListener goCom = new OnClickListener() {
		
		
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent i=new Intent(Lvcomdetail.this, Lvcommenterr.class);
			
			i.putExtras(getIntent().getExtras());
			i.putExtra("lang", getLang());
			i.putExtra("database", getDatabase());
			i.putExtra("em",emp);
			
			i.putExtra("project", pr);
			i.putExtra("oneerr", oneer);
			
			startActivity(i);
		}
	};
	
	private OnClickListener listenerLogout=new OnClickListener() {
		
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent i=new Intent(Lvcomdetail.this, LogoutActivity.class);
			i.putExtra("database", getDatabase());
			startActivity(i);
		}
	};
}
